﻿using UnityEngine;
using System.Collections;

public class RoleUnitObject : UnitObject
{
    MeshRenderer renderer = null;

    public RoleUnitObject(nUnitData data, int layer) :
        base(data, layer)
    {

    }

    public override void Load()
    {
        base.Load();

        GameObject res =  ZoneManager.Instance._ZoneMediaManager.GetResource3DObject<GameObject>(_unitData);

        GameObject go = GameObject.Instantiate<GameObject>(res);

        renderer = go.GetComponent<MeshRenderer>();

        go.layer = _Object.layer;

        go.transform.parent = _Object.transform;

        go.transform.position = _unitData._Pos;

        go.transform.localScale = Vector3.one * _unitData.spine_zone_scale;

        AdjustPos(go);

        _SR.enabled = false;
    }

    /// <summary>
    /// 调整到菱形中央
    /// </summary>
    /// <param name="go"></param>
    void AdjustPos(GameObject go)
    {
        Vector3 offset = _Object.transform.position;

        offset.y += ZoneCfg.RhombusMin / ZoneCfg.RhombusFactor / 2;
        offset.x += ZoneCfg.RhombusMin / 2;

        go.transform.position = offset;

    }

    public override void SetSortingOrder(int sorting)
    {
        base.SetSortingOrder(sorting);

        renderer.sortingOrder = sorting;
    }

    public override bool Save()
    {
        return base.Save();
    }

    public override void Unload()
    {
        base.Unload();
    }

    public override bool isHitTransparent
    {
        get
        {
            return false;
        }
    }
}
